package com.yf.exam.gpt.dashscope;

import com.yf.exam.score.bean.ScoreGptRequest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author : xascgcs
 */
public class DashScopeUtils {

    private static final String SCORE_START_FLAG = "gpt-score-start";

    private static final String SCORE_END_FLAG = "gpt-score-end";

    private static final String DESCRIBE_START_FLAG = "gpt-describe-start";

    private static final String DESCRIBE_END_FLAG = "gpt-describe-end";

    public static String getGptQuest(ScoreGptRequest gptRequest) {
        return "标准答案是：" + gptRequest.getStandardAnswer() + "，\n"
                + "学生的答案是：" + gptRequest.getUserAnswer()  + "，\n"
                + "请判断AB答案的相似度为多少，完全相似为100， 完全不相似为0" + "，\n"
                + "请直接给出一个数字值和文字说明内容" + "。\n"
                + "数字值用"+ SCORE_START_FLAG +"开始，用"+ SCORE_END_FLAG +"结束" + "。\n"
              ;
    }

    public static int getScoreByContent(String content){
        int start = content.indexOf(SCORE_START_FLAG);
        int end = content.indexOf(SCORE_END_FLAG, start);
        int length = content.length();
        if(start != -1 && end != -1 && end > start && end < length){
            String substring = content.substring(SCORE_START_FLAG.length() + start + 1, end);
            return Integer.parseInt(substring.trim());
        }
        return 0;
    }

    public static String getDescribeByContent(String content){
        System.out.println("content"+content);
        int start = content.indexOf(SCORE_START_FLAG);
        int end = content.indexOf(SCORE_END_FLAG, start);
        int length = content.length();
        if(start != -1 && end != -1 && end > start && end < length){
            return content.substring(SCORE_END_FLAG.length() +end + 1, length);
        }
        return "";
    }
}
